package exercises.leetcode;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年11月13日 时间: 22:40
 */
public class No5911$211113 {
    private static class Robot {

        int width;
        int height;
        int steps;
        int perimeter;

        public Robot(int width, int height) {
            this.height = height;
            this.width = width;
            perimeter = height * 2 + width * 2 - 4;
            steps = 0;
        }

        public void move(int num) {
            if (num % perimeter == 0 && steps == 0 && num > 0) steps = perimeter;
            num %= perimeter;
            steps += num;
            if (steps > perimeter) steps++;
            steps %= perimeter + 1;
        }

        public int[] getPos() {
            if (steps < width) return new int[]{steps, 0};
            if (steps <= perimeter / 2) return new int[]{width - 1, steps - width + 1};
            if (steps <= perimeter - height + 1) return new int[]{perimeter - height + 1 -steps, height - 1};
            return new int[]{0, perimeter - steps};
        }

        public String getDir() {
            if (steps < width) return "East";
            if (steps <= perimeter / 2) return "North";
            if (steps <= perimeter - height + 1) return "West";
            return "South";
        }
    }
}
